home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / gse1.doc < prev    next >
Text File  |  1995-03-31  |  8KB  |  181 lines

  1. GSE1 Directory - Goal Seeking Engine version 1 - 4/91   [**SHAREWARE**] 
  2. Copyright 1991, Jeff Duncombe 
  3. [Included on Goodies Disk #3 with the author's permission.  -jkh-] 
  4.  
  5.         What if one program could find out the fewest number of floppies to 
  6. copy your enormous number of files onto?  Or maybe balance your checkbook? 
  7. What about making perfectly timed audio cassettes? 
  8.  
  9.         GSE is a utility for finding what combination of a group of numbers 
  10. will total to a goal number (within a certain accuracy).  There are many 
  11. applications that are tailor-made to this type of an engine; three are provided 
  12. for example. 
  13.  
  14.         The basic stack setup is as follows: 
  15.  
  16.         3:[Vector of numbers] 
  17.         2:Goal                          =====> 
  18.         1:Accuracy                              1:[Answer Vector] 
  19.  
  20.         For example, assume there are a group of numbers: 6, 4, 3, 2.  What 
  21. combination of these numbers will equal 7? 
  22.  
  23.         Load the stack as follows: 
  24.         3: [6 4 3 2]                    yields 
  25.         2: 7                            =====> 
  26.         1: 0                                            1: [0 4 3 0] 
  27.  
  28.         This means that of the four item list, the combination of 4 and 3 will 
  29. yield the goal of 7. 
  30.  
  31.         Not very exciting, you say?  Here's a better one: you have a directory 
  32. of 8 files (100K, 230K, 310K, 130K, 170K, 50K, 260K, 190K).  Assume that you 
  33. want to put these onto the fewest number of 360K floppies.  If you total them 
  34. (put the vector in level 1 and CNRM), you will find they total 1440K, or 4 x 
  35. 360K disks.  But if you use the standard COPY command, they will end up taking 
  36. 5 diskettes, as follows: 
  37.  
  38. 100K   230K |  310K  | 130K   170K |  50K   260K |   190K 
  39.   Disk 1    | Disk 2 |   Disk 3    |    Disk 4   |  Disk 5 
  40.  
  41.         This is a problem for GSE; it will find you a way using only 4 disks! 
  42. (Hint: It is a good idea to have the original vector in 3 and 4, so a copy will 
  43. still be available). 
  44.  
  45.         Load the stack: 
  46.         4:[100 230 310 130 170 50 260 190] 
  47.         3:[100 230 310 130 170 50 260 190] 
  48.         2:360                   =====>  2:[100 230 310 130 ...] 
  49.         1:0                             1:[100 0 0 0 0 0 260 0] 
  50.  
  51.         The first answer: 100K and 260K should fill the first disk.  Notice 
  52. that flag 1 is set on the screen, which means that the goal of 360 was found 
  53. within the desired accuracy of 0.  If flag 1 was clear, the best answer would 
  54. be displayed, but it wouldn't be within the limits. 
  55.  
  56.         Now press [-] (the minus key) and [ENTER].  This will take out the 
  57. known solution from the list and leave you with the next argument (properly 
  58. DUPlicated).  Fill 1 & 2 with the desired info and try it again: 
  59.  
  60.         4:[0 230 310 130 170 50 0 190] 
  61.         3:[0 230 310 130 170 50 0 190] 
  62.         2:360                           =====>  2:[0 230 310 130 17...] 
  63.         1:0                                     1:[0 230 0 130 0 0 0 0] 
  64.  
  65.         The next answer is 230K and 130K.  After a [-], [ENTER], 360 and 0, you 
  66. continue: 
  67.  
  68.         4:[0 0 310 0 170 50 0 190] 
  69.         3:[0 0 310 0 170 50 0 190] 
  70.         2:360                           =====>  2:[0 0 310 0 170 50...] 
  71.         1:0                                     1:[0 0 310 0 0 50 0 0] 
  72.  
  73.         The third disk shall hold the 310K file and the 50K file.  [-], 
  74. [ENTER], 360, 0: 
  75.  
  76.         4:[0 0 0 0 170 0 0 190] 
  77.         3:[0 0 0 0 170 0 0 190] 
  78.         2:360                           =====>  2:[0 0 0 0 170 0 0 ...] 
  79.         1:0                                     1:[0 0 0 0 170 0 0 190] 
  80.  
  81.         The fourth and final disk should therefore hold 170K and 190K.   
  82.  
  83.         The possibilities are endless.  As another example, say that you needed 
  84. to balance your checkbook.  Just type in a vector of all the checks that you 
  85. wrote, then set your final balance as the goal (don't forget any little bank 
  86. fees).  Follow the example below: 
  87.  
  88.         You've written checks for $32.56, $27.90, $130.21, and $46.35.  Your 
  89. total for checks written is $106.81.  Solve: 
  90.  
  91.         3:[32.56 27.90 130.21 46.35] 
  92.         2:106.81                        =====> 
  93.         1:0                                     1:[32.56 27.9 0 46.35] 
  94.  
  95.         The check for 130.21 must still be uncashed. 
  96.  
  97.         As the last example, I will use the problem that inspired me to write 
  98. this program in the first place.  I want to tape some songs from CD to audio 
  99. cassette.  The cassette is 45 minutes on each side, for a total of 90 minutes. 
  100. There should be a way to place the songs selectively on each side so as to fit 
  101. every song in its entirety.  This is more difficult than it sounds, if you 
  102. don't have a computer, because there are generally 20+ songs to deal with. 
  103. Anyway, here are the song lengths (in seconds): 
  104.  
  105.                 [540 482 669 841 334 592 604 612 381 344] 
  106.  
  107. The goal is 2700 seconds (45 minutes).  The accuracy will be 0. 
  108.  
  109.         4:[540 482 669 841 ...] 
  110.         3:[540 482 669 841 ...] 
  111.         2:2700                          =====>  2:[540 482 669 841 ...] 
  112.         1:0                                     1:[540 0 0 841 334 ...] 
  113.  
  114.         The first side of the tape must contain the songs the are lengths 540, 
  115. 841, 334, 604, and 381 for a total of exactly 2700 seconds.  A simple [-] and 
  116. you get what songs go on the second side (482, 669, 592, 612, and 344). 
  117.  
  118.         That's it for the examples.  Here are just a few random specs to help 
  119. you on your way: 
  120.  
  121. * This engine uses error checking, so don't worry about your arguments causing 
  122. a system crash. 
  123.  
  124. * Flags 1, 2, & 3 are used by this program.  They are all cleared at the 
  125. beginning and modified during the course of the execution.  Their descriptions 
  126. are as follows: 
  127.  
  128.                 Set                     Clear 
  129.  
  130. Flag 1:         The answer is within    The answer is the closest to 
  131.                 the desired accuracy.   the accuracy as possible, but 
  132.                                         NOT within it. 
  133.  
  134. Flag 2:         The argument is a two-  The program runs normally. 
  135.                 dimensional array. 
  136.                 The arguments are left 
  137.                 alone. 
  138.  
  139. Flag 3:         (This flag is always clear at the end of the engine) 
  140.  
  141. * If a complex vector is given as an argument, it will be converted to the real 
  142. part only.  Example: [(2,3) (4,5) (6,4) (3,2)] would be considered to be [2 4 6 
  143. 3]. 
  144.  
  145. Note: The [-] still works with a complex and a real-only vector, as shown: 
  146.  
  147.         2:[(2,3) (4,5) (6,4)]    [-] 
  148.         1:[0 4 0]               =====>  1:[(2,3) (0,5) (6,4)] 
  149.  
  150. * Although GSE appears to be the only program in the GSE1 directory, there are 
  151. three "hidden" files called GSEV, GSER, and MMUL.  These programs are 
  152. subroutines of GSE, and should not be used alone, for they can cause a Memory 
  153. Clear if not used correctly.  GSE uses them correctly, so they are hidden from 
  154. the VAR menu.  But this means that the GSE program cannot be removed from the 
  155. GSE1 directory and used alone.  If you wish to call GSE from your own software, 
  156. you may make the GSE1 directory into a library.  [See USRLIB on EduCALC Goodies 
  157. Disk #1.  -jkh-] 
  158.  
  159. Now for the disclaimer: 
  160. This program contains undocumented features of the HP 48SX and consequently I 
  161. bear no responsibility for any damage it may cause.  (I haven't ever had a 
  162. problem, though). 
  163.  
  164. If you decide that this engine is worth while to use in your personal or 
  165. commercial applications, I would appreciate some compensation for this.  This 
  166. first version contains only the "bare-bones" of what I have envisioned this 
  167. application to be.  Future releases shall include batch goal-seeking (having 
  168. multiple goals with the same vector and minimizing the overall difference), 
  169. speed enhancements (in theory there should be a big future for this one), and 
  170. some bonus features.  Remember, the only way to be alerted to these changes is 
  171. to register for that privilege.  Send your donations to: 
  172.  
  173. Jeff Duncombe 
  174. PO Box 20098 
  175. Fountain Valley, CA 92708 
  176.  
  177. (Suggested amounts are $10 for personal use, commercial royalties may 
  178. vary.  Contact me for details.) 
  179.  
  180. Happy Goal Seeking! 
  181.